#include <slothttpd/config/formatter.hpp>
#include <slothttpd/http/request.hpp>
#include <slothttpd/config/configuration.hpp>
#include <slothttpd/config/server.hpp>

#include <string>
#include <vector>
#include <iterator>

#include <boost/range/algorithm.hpp>

using namespace slothttpd;

const std::string request_string = 
        "GET /%4eakfile.html HTTP/1.1\r\n"
        "Host: example.org\r\n"
        "\r\n";

template<typename Containter>
void copy(const std::string &src, Containter &out)
{
    boost::range::copy(src, std::back_inserter(out));
}

char_range_t make(std::vector<char> &v)
{
    return char_range_t(v.data(), v.data() + v.size());
}

int main()
{
    const std::string method_string = "GET";
    const std::string path_string   = "/%4dakfile.html";
    const std::string query_string  = "key=value&key2=%4d%4d";
    
    std::vector<char> method;
    std::vector<char> path;
    std::vector<char> query;
    
    copy(method_string, method);
    copy(path_string, path);
    copy(query_string, query);
    
    http::request req;
    
    req.method = make(method);
    req.path = make(path);
    req.query_string = make(query);
    
    boost::asio::io_service ios;
    
    auto cfg = config::configuration::from_file("config.json", ios);
    auto &loc = *cfg->servers.at(0)->locations.at(0);
    
    std::vector<char> vec(1000);
    char_range_t r = make(vec);
    
    req.unescape_path();
    
    config::formatter("method: %m\nserver_path: %s\npath: %u\nquery: %q\n", loc).place(r, req);
    
    std::cout << char_range_t(vec.data(), r.begin());
    
}




